function checkValidate(input, inputErr, pattern) {
    if (!validate(input.val(), pattern)) {
        inputErr.html("Incorrectly input!");
        input.css("border-color", "#ef3124");
        return false;
    } else {
        input.css("border-color", "#79c30c");
        inputErr.html("");
        return true;
    }
}

function checkValidateConfPassword(confPassword, password, confPasswordTip, passwordPattern) {
        if (confPassword.val() === password.val()
//                && confPassword.val() !== "" 
                && validate(confPassword.val(), passwordPattern)) {
            confPassword.css("border-color", "#79c30c");
            confPasswordTip.html("");
            return true;
        } else {
            confPasswordTip.html("Incorrectly input!");
            confPassword.css("border-color", "#ef3124");
            return false;
        }
    }

function validate(value, pattern) {
    var reg = new RegExp(pattern);
    return reg.test(value);
}

function toTranslit(text) {
    return text.replace(/([а-яё])|([\s_-])|([^a-z\d])/gi,
            function(all, ch, space, words, i) {
                if (space || words) {
                    return space ? ' ' : '';
                }
                var code = ch.charCodeAt(0),
                        index = code == 1025 || code == 1105 ? 0 :
                        code > 1071 ? code - 1071 : code - 1039,
                        t = ['yo', 'a', 'b', 'v', 'g', 'd', 'e', 'zh',
                    'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p',
                    'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh',
                    'shch', '', 'y', '', 'e', 'yu', 'ya'
                ];
                return t[index];
            });
}


